{% extends 'base.html' %}

{% block body %}

{% include('idp-modal.html') %}

{# Modal for team creation #}
<div class='modal fade' id='createTeamModal' tabindex='-1' role='dialog' aria-labelledby='createTeamModalLabel'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='createTeamModalLabel'>{{ 'Create team'|trans }}</h5>
        <button type='button' class='close' data-dismiss='modal' aria-label='{{ 'Close'|trans }}'>
          <span aria-hidden='true'>&times;</span>
        </button>
      </div>
      <div class='modal-body' data-wait='{{ 'Please wait…'|trans }}'>
        <label for='newTeamName'>{{ 'Name'|trans }}</label>
        <input type='text' placeholder='{{ 'Enter team name'|trans }}' id='newTeamName' class='form-control' aria-label='{{ 'Enter team name'|trans }}'>
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-ghost' data-dismiss='modal'>{{ 'Cancel'|trans }}</button>
        <button type='button' data-action='create-team' class='btn btn-primary' data-dismiss='modal'>{{ 'Create'|trans }}</button>
      </div>
    </div>
  </div>
</div>
{# display current and latest version #}
<p>{{ 'Installed version:'|trans }} <span id='currentVersion'>{{ constant('Elabftw\\Elabftw\\App::INSTALLED_VERSION') }}</span>
<br>
{{ 'Latest stable version:'|trans }} <span id='latestVersion'></span>

{# show error if the email is not configured #}
{% if App.Config.configArr.mail_from == 'notconfigured@example.com' %}
    {{ 'Email configuration is required. Consult the documentation (%slink%s) for help.'|trans|format("<a href='https://doc.elabftw.net/sysadmin-guide.html#setting-up-email'>", "</a>")|msg('ko') }}
{% endif %}

<div id='versionNotifZone'></div>

<ul class='tabbed-menu'>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='1'>{{ 'Server'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='2'>{{ 'Teams'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='3'>{{ 'Users'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='4'>{{ 'Communication'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='5'>{{ 'Email'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='6'>{{ 'Security'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='7'>{{ 'Policies'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='8'>{{ 'Uploads'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='9'>{{ 'Timestamp'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='10'>{{ 'Local auth'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='11'>SAML</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='12'>LDAP</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='13'>{{ 'External auth'|trans }}</button></li>
  <li><button type='button' class='btn' data-action='switch-tab' data-tabtarget='14'>{{ 'Audit Logs'|trans }}</button></li>
</ul>

{# loading spinner #}
<div class='d-flex justify-content-center' id='loading-spinner'>
  <div class='lds-dual-ring'></div>
</div>

{# TAB 1 SERVER #}
<div data-tabcontent='1' hidden>
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Usage Statistics'|trans }}</h3>
  <div class='pl-3 mb-5'>
    <h4>{{ 'Users'|trans }}</h4>
    <div class='d-flex justify-content-between'>
      <div>{{ 'Teams'|trans }}: {{ info.teams_count }} &ndash; {{ 'Members'|trans }}: {{ info.active_users_count }} &ndash; {% trans %}Experiment{% plural info.experiments_count %}Experiments{% endtrans %}: {{ info.experiments_count }} ({{ info.experiments_timestamped_count }} timestamped) &ndash; {{ 'Resources'|trans }}: {{ info.items_count }}</div>
      <div><a href='/api/v2/reports?format=csv&scope=instance' class='btn btn-primary'>{{ 'Get users report'|trans }}</a></div>
    </div>

    <h4>{{ 'Stored containers'|trans }}</h4>
    <div class='d-flex justify-content-between'>
      <div>{{ 'Stored containers: %d bound to experiments and %d bound to resources'|trans|format(containersCount.experiments, containersCount.items) }}</div>
      <div><a href='/api/v2/reports?format=csv&scope=stored_compounds' class='btn btn-primary'>{{ 'Get inventory report'|trans }}</a></div>
    </div>
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Settings'|trans }}</h3>
  <div class='pl-3'>

    <div class='d-flex justify-content-between'>
      <label for='lang' class='col-form-label'>{{ 'Language'|trans }}</label>
      <select id='lang' data-trigger='change' data-model='config' data-target='lang' class='form-control col-md-3' autocomplete='off'>
        {% for lang, text in langsArr|sort %}
        <option {{ App.Config.configArr.lang == lang ? ' selected' }} value='{{ lang }}'>{{ text }}</option>
        {% endfor %}
      </select>
    </div>
    <p class='smallgray'>{{ 'The default language of this instance. It can be overridden by each user.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='proxy' class='col-form-label'>{{ 'Address of the Proxy'|trans }}</label>
      <input class='form-control col-md-3' data-trigger='blur' data-model='config' data-target='proxy' type='text' value='{{ App.Config.configArr.proxy }}' id='proxy' />
    </div>
    <p class='smallgray'>{{ 'If you are behind a firewall/proxy, enter the address here. Example: http://proxy.example.com:3128'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='support_url' class='col-form-label'>{{ 'URL where the Support menu entry from Help dropdown points'|trans }}</label>
      <input class='form-control col-md-3' type='url' value='{{ App.Config.configArr.support_url }}' data-trigger='blur' data-model='config' data-target='support_url' id='support_url' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='chat_url' class='col-form-label'>{{ 'URL where the Chat room menu entry from Help dropdown points'|trans }}</label>
      <input class='form-control col-md-3' type='url' value='{{ App.Config.configArr.chat_url }}' data-trigger='blur' data-model='config' data-target='chat_url' id='chat_url' />
    </div>
    <hr>

    {% include 'binary-setting.html' with {'label': 'Allow users to change their first name, last name, internal id or email address'|trans, 'slug': 'allow_users_change_identity', 'help': 'When disabled, only a Sysadmin will be allowed to modify these parameters.'|trans} %}

    {% include 'binary-setting.html' with {'label': 'Prevent modification of global compounds database unless user is given explicit rights.'|trans, 'slug': 'compounds_require_edit_rights', 'help': 'When enabled, a Sysadmin will need to give edit rights to all users that should be able to edit the common compounds database. All other users will access it in read-only.'|trans} %}

    {% include 'binary-setting.html' with {'label': 'Prevent modification of inventory locations unless user is given explicit rights.'|trans, 'slug': 'inventory_require_edit_rights', 'help': 'When enabled, a Sysadmin will need to give edit rights to all users that should be able to edit the inventory locations. All other users will access it in read-only.'|trans} %}

  </div>


  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Revisions system configuration'|trans }}</h3>
  <div class='pl-3'>
    <div class='d-flex justify-content-between'>
      <label for='max_revisions' class='col-form-label'>{{ 'Maximum number of stored revisions per entry'|trans }}</label>
      <input class='form-control col-md-3' data-trigger='blur' data-model='config' data-target='max_revisions' type='number' min='0' max='999' value='{{ App.Config.configArr.max_revisions }}' id='max_revisions' />
    </div>
    <p class='smallgray'>{{ 'Setting this to a low value will help keeping the database size small. Setting this to 0 will allow infinite number of revisions stored.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='min_delta_revisions' class='col-form-label'>{{ 'Minimum number of characters that need to be changed in order to create a new revision per entry'|trans }}</label>
      <input class='form-control col-md-3' type='number' min='1' max='999' value='{{ App.Config.configArr.min_delta_revisions }}' data-trigger='blur' data-model='config' data-target='min_delta_revisions' id='min_delta_revisions' />
    </div>
    <p class='smallgray'>{{ 'Setting this to a high value will help keeping the database size small.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='min_days_revisions' class='col-form-label'>{{ 'Number of days between changes to automatically create a revision'|trans }}</label>
      <input class='form-control col-md-3' type='number' min='1' max='999' value='{{ App.Config.configArr.min_days_revisions }}' data-trigger='blur' data-model='config' data-target='min_days_revisions' id='min_days_revisions' />
    </div>
    <p class='smallgray'>{{ 'If the last change is at least this days old, a revision will be created regardless of the minimum characters setting.'|trans }}</p>
    <hr>
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Permissions settings'|trans }}</h3>
  <div id='permissionsSettingsDiv' class='pl-3'>
    {% for perm in permissions %}
      {% include 'binary-setting.html' with {'label': 'Allow the base permission setting «' ~ perm.toHuman|trans ~ '»', 'slug': perm.configKey} %}
    {% endfor %}
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Registration and authentication configuration'|trans }}</h3>
  <div class='pl-3'>

    {% include 'binary-setting.html' with {'label': 'Allow anonymous visitors to login and see Public experiments'|trans, 'slug': 'anon_users', 'help': 'This allows users without an account to login into a team and see the experiments with public visibility. It also enables users to share specific entries with a special link.'|trans} %}

    {% include 'binary-setting.html' with {'label': 'Switch this instance in open science mode'|trans, 'slug': 'open_science', 'help': 'This allows search engines to crawl the site. Visitors will be automatically logged in in the specified team.'|trans} %}

    <div class='d-flex justify-content-between'>
      <label for='open_team' class='col-form-label'>{{ 'Select which team will be open to the world in open science mode'|trans }}</label>
      <select id='open_team' data-trigger='change' data-model='config' data-target='open_team' class='form-control col-md-3'>
        {% for team in teamsArr %}
          <option {{ App.Config.configArr.open_team == team.id ? ' selected' }} value='{{ team.id }}'>{{ team.name }}</option>
        {% endfor %}
      </select>
    </div>
    <p class='smallgray'>{{ 'This has no effect if open science mode is disabled.'|trans }}</p>
    <hr>

    {% include 'binary-setting.html' with {'label': 'Admins can create local accounts'|trans, 'slug': 'admins_create_users'} %}
    {% include 'binary-setting.html' with {'label': 'Allow Admins to add existing users to their team'|trans, 'slug': 'admins_import_users'} %}
    {% include 'binary-setting.html' with {'label': 'Allow Admins to archive users'|trans, 'slug': 'admins_archive_users'} %}


    <div class='d-flex justify-content-between'>
      <label for='user_msg_need_local_account_created' class='col-form-label'>{{ 'Message shown to user after successful external auth but local account provisioning is required'|trans }}</label>
      <input class='form-control col-md-3' data-trigger='blur' data-model='config' data-target='user_msg_need_local_account_created' type='text' autocomplete='off' value='{{ App.Config.configArr.user_msg_need_local_account_created }}' id='user_msg_need_local_account_created' />
    </div>
    <hr>
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Remote directory configuration'|trans }}</h3>
  <div class='pl-3'>
    {% include 'binary-setting.html' with {'label': 'Admins can create local accounts from remote directory'|trans, 'slug': 'admins_create_users_remote_dir'} %}

    <div class='d-flex justify-content-between'>
      <label for='remote_dir_service' class='col-form-label'>{{ 'Remote directory service'|trans }}</label>
      <input class='form-control col-md-3' data-trigger='blur' data-model='config' data-target='remote_dir_service' type='text' value='{{ App.Config.configArr.remote_dir_service }}' id='remote_dir_service' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='remote_dir_config' class='col-form-label'>{{ 'Remote directory configuration'|trans }}</label>
      <input class='form-control col-md-3' data-trigger='blur' data-model='config' data-target='remote_dir_config' type='text' autocomplete='off' value='{{ App.Config.configArr.remote_dir_config }}' id='remote_dir_config' />
    </div>
    <p class='smallgray'>{{ 'Use a JSON string for configuration. This setting is stored encrypted.'|trans }}</p>
    <hr>
  </div>


  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Information'|trans }}</h3>
  <div class='pl-3'>
    <ul class='list-group'>
      <li class='list-group-item'>{{ 'Operating System'|trans }}: {{ phpInfos.0 }}</li>
      <li class='list-group-item'>{{ 'Docker image version'|trans }}: {{ elabimgVersion }}</li>
      <li class='list-group-item'>{{ 'PHP Version'|trans }}: {{ phpInfos.1 }}</li>
      <li class='list-group-item'>{{ 'MySQL Version'|trans }}: {{ phpInfos.6 }}</li>
      <li class='list-group-item'>{{ 'MySQL database structure version'|trans }}: {{ App.Config.configArr.schema }}</li>
      <li class='list-group-item'>{{ 'Largest integer supported'|trans }}: {{ phpInfos.2 }}</li>
      <li class='list-group-item'>{{ 'PHP configuration directory'|trans }}: {{ phpInfos.3 }}</li>
      <li class='list-group-item'>{{ 'Maximum file size for uploaded files'|trans }}: {{ phpInfos.4 }}</li>
      {% if phpInfos.5|length > 1 %}
        <li class='list-group-item'>{{ 'Timezone'|trans }}: {{ phpInfos.5 }}</li>
      {% endif %}
    </ul>
  </div>
</div>

{# TAB 2 TEAMS #}
<div data-tabcontent='2' hidden>
  <h3 class='mb-3 p-2 pl-3 section-title' id='teamsSectionTitle'>{{ 'Teams list'|trans }}</h3>
  <div id='teamsDiv' class='pl-3'>
    <div class='mb-3 d-flex justify-content-between'>
      <p class='col-form-label'>{{ 'This page allows you to edit the teams present on this instance.'|trans }} (<a href='https://doc.elabftw.net/sysadmin-guide.html#configure-teams-optional' target='_blank' rel='noopener' class='external-link'>{{ 'Documentation'|trans|lower }}</a>)</p>
      {# CREATE NEW BUTTON the div around the button is necessary or the button itself gets resized on small viewports #}
      <div>
        <button type='button' class='btn btn-primary' data-action='toggle-modal' data-target='createTeamModal'>{{ 'Create a team'|trans }}</button>
      </div>
    </div>

    {% include 'filter-input-snippet.html' with {'target': 'teamsTableBody'} %}
    <div class='table-container'>
      <table id='teamsTable' class='table' aria-describedby='teamsSectionTitle' data-table-sort='true'>
        <thead>
          <tr>
            <th scope='col'>{{ 'ID'|trans }}</th>
            <th scope='col'>{{ 'Name'|trans }}</th>
            <th scope='col'>{{ 'Organisation ID'|trans }}</th>
            <th scope='col'>{{ 'Creation date'|trans }}</th>
            <th scope='col'>{{ 'Visible'|trans }}</th>
            <th scope='col'>{{ 'Actions'|trans }}</th>
          </tr>
        </thead>
        <!-- [html-validate-disable-block prefer-native-element: suppress error from malle] -->
        <tbody id='teamsTableBody'>
          {% for team in teamsArr %}
          {# commented out because scales very badly obviously and makes loading sysconfig page super slow #}
          {#{% set count = Teams.getStats(team.id) %}#}
            <tr>
              <td>{{ team.id }}</td>
              <td><span class='hl-hover-gray p-1 rounded malleableColumn' data-endpoint='teams' data-id='{{ team.id }}' data-target='name'>{{ team.name }}</span>
                {#
                <p class='smallgray p-1'>{{ 'Members'|trans }}: {{ count.totusers }} &ndash;
                {% trans %}
                Experiment
                {% plural count.totxp %}
                Experiments
                {% endtrans %}
                : {{ count.totxp }} ({{ count.totxpts }} timestamped) &ndash; {{ 'Resources'|trans }}: {{ count.totdb }}<p>
                #}

              </td>
              <td><span class='hl-hover-gray p-1 rounded malleableColumn' data-endpoint='teams' data-id='{{ team.id }}' data-target='orgid'>{{ team.orgid|default('Not set'|trans) }}</span></td>
              <td>{{ team.created_at }}</td>
              <td>
                <label class='switch ucp-align'>
                  <input type='checkbox' data-trigger='change' data-model='teams/{{ team.id }}' data-target='visible' {{ team.visible == 1 ? 'checked="checked"' }}>
                  <span class='slider'></span>
                  <span class='sr-only'>{{ team.name }} - {{ 'Visible'|trans }}</span>
                </label>
              </td>
              <td>
                {% if count.all_users_count == 0 and team.id != App.Users.userData.team %}
                <span data-id='{{ team.id }}' id='teamsDestroyButton_{{ team.id }}' data-action='destroy-team' class='p-1 rounded hover-danger'>
                  <i class='fas fa-trash-alt'></i>
                </span>
                {% else %}
                  <em class='text-muted'>{{ 'None available'|trans }}</em>
                {% endif %}
              </td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
</div>

{# TAB 3 USERS #}
<div data-tabcontent='3' hidden>
  {% include 'editusers.html' %}
</div>

{# TAB 4 - Communication #}
<div data-tabcontent='4' hidden>
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Announcement'|trans }}</h3>
  <div class='pl-3 mb-5'>
    <label for='announcementInput' class='mb-3'>{{ "The following text will be displayed to all users on all pages while it's active."|trans }}</label>
    <div class='input-group'>
      <input class='form-control' type='text' id='announcementInput' name='announcement' value='{{ App.Config.configArr.announcement }}' />
      <div class='input-group-append'>
        <button type='button' data-action='patch-announcement' data-operation='save' data-inputid='announcementInput' class='btn btn-primary'>{{ 'Save'|trans }}</button>
      </div>
      <div class='input-group-append'>
        <button type='button' data-action='patch-announcement' data-operation='clear' data-inputid='announcementInput' class='btn btn-danger'>{{ 'Clear'|trans }}</button>
      </div>
    </div>
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Login page announcement'|trans }}</h3>
  <div class='pl-3 mb-5'>
    <label for='loginAnnouncementInput' class='mb-3'>{{ 'The following text will be displayed only on the login page.'|trans }}</label>
    <div class='input-group'>
      <input class='form-control' type='text' id='loginAnnouncementInput' name='login_announcement' value='{{ App.Config.configArr.login_announcement }}' />
      <div class='input-group-append'>
        <button type='button' data-action='patch-announcement' data-operation='save' data-inputid='loginAnnouncementInput' class='btn btn-primary'>{{ 'Save'|trans }}</button>
      </div>
      <div class='input-group-append'>
        <button type='button' data-action='patch-announcement' data-operation='clear' data-inputid='loginAnnouncementInput' class='btn btn-danger'>{{ 'Clear'|trans }}</button>
      </div>
    </div>
  </div>

  {# ONBOARDINGELCOME EMAIL #}
  {% set model = 'config' %}
  {% set src = App.Config.configArr %}
  {% include 'onboarding-email.html' %}

  {# MASS EMAIL #}
  <h3 class='p-2 pl-3 section-title'>{{ 'Send a Mass Email'|trans }}</h3>
  <form class='pl-3 mt-2 mb-5' aria-label='{{ 'Send a Mass Email'|trans }}' id='massEmailForm'>
    {{ App.Session.get('csrf')|csrf }}
    <input type='hidden' name='action' value='email'>
    <label>{{ 'Send to'|trans }}</label>
    <div class='form-check'>
      <input class='form-check-input' type='radio' name='target' value='active_users' id='targetAll' checked> <label class='form-check-label' for='targetAll'>{{ 'All active users'|trans }}</label>
    </div>

    <div class='form-check'>
      <input class='form-check-input' type='radio' name='target' value='admins' id='targetAdmins'> <label class='form-check-label' for='targetAdmins'>{{ 'All active admins'|trans }}</label>
    </div>

    <div class='form-check'>
      <input class='form-check-input' type='radio' name='target' value='sysadmins' id='targetSysadmins'> <label class='form-check-label' for='targetSysadmins'>{{ 'All active sysadmins'|trans }}</label>
    </div>
    <label for='massSubject' class='col-form-label'>{{ 'Email Subject'|trans }}</label>
    <input class='form-control col-md-12' name='subject' type='text' required id='massSubject' size='45' />

    <label for='massBody' class='col-form-label mt-2'>{{ 'Email Body'|trans }}</label>
    <textarea class='form-control col-md-12' name='body' id='massBody'></textarea>
    <div class='mt-4 text-center'>
      <button type='submit' data-action='send-mass-email' class='btn btn-primary'>{{ 'Send'|trans }}</button>
    </div>
  </form>
</div>

{# TAB 5 EMAIL #}
<div data-tabcontent='5' hidden>
  <p>{{ "Without a valid way to send emails, users won't be able to reset their password. It is recommended to create a specific %ssmtp2go.com%s account and add the information here."|trans|format("<a href='https://www.smtp2go.com/?s=eLabFTW'>", "</a>")|raw }}</p>
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'E-mail Settings'|trans }}</h3>
  <div class='pl-3' id='emailSettings'>

    <div class='d-flex justify-content-between'>
      <label for='smtp_address' class='col-form-label'>{{ 'Address of the SMTP server'|trans }}</label>
      <input class='form-control col-md-3' type='text' value='{{ App.Config.configArr.smtp_address }}' placeholder='mail.smtp2go.com' data-trigger='blur' data-model='config' data-target='smtp_address' id='smtp_address' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='smtp_port' class='col-form-label'>{{ 'SMTP Port'|trans }}</label>
      <input class='form-control col-md-3' type='number' placeholder='587' value='{{ App.Config.configArr.smtp_port }}' data-trigger='blur' data-model='config' data-target='smtp_port' id='smtp_port' />
    </div>
    <p class='smallgray'>{{ 'Default is 587.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='smtp_username' class='col-form-label'>{{ 'SMTP username'|trans }}</label>
      <input class='form-control col-md-3' type='text' value='{{ App.Config.configArr.smtp_username }}' data-trigger='blur' data-model='config' data-target='smtp_username' id='smtp_username' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='smtp_password' class='col-form-label'>{{ 'SMTP password'|trans }}</label>
      {% if App.Config.configArr.smtp_password|length == 0 %}
        <div class='input-group col-md-3 p-0'>
          <input class='form-control' type='password' data-trigger='blur' data-model='config' data-target='smtp_password' id='smtp_password' autocomplete='off' />
          <div class='input-group-append'>
            <button type='button' class='btn btn-light input-border' data-action='toggle-password' title='{{ 'Show password'|trans }}' aria-label='{{ 'Show password'|trans }}'><i class='fas fa-eye' aria-hidden='true'></i></button>
          </div>
        </div>
      {% else %}
        <p>
        {{ 'A password is already set.'|trans }} <button type='button' class='btn btn-danger btn-sm' data-action='clear-password' data-target='smtp' data-reload='emailSettings'>{{ 'Clear'|trans }}</button>
        </p>
      {% endif %}
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='mail_from' class='col-form-label'>{{ 'Sender address'|trans }}</label>
      <input class='form-control col-md-3' type='email' value='{{ App.Config.configArr.mail_from }}' data-trigger='blur' data-model='config' data-target='mail_from' id='mail_from' />
    </div>
    <hr>

    {% include 'binary-setting.html' with {'label': 'Verify TLS certificate'|trans, 'slug': 'smtp_verify_cert'} %}

    {% include 'binary-setting.html' with {'label': 'Send mass emails grouped'|trans, 'slug': 'email_send_grouped', 'help': 'When enabled, mass emails are sent as a single email with all recipients in Bcc. Disable this setting if you encounter issues with your SMTP server refusing to deliver emails if a recipient has an invalid account or if there are too many recipients.'} %}

  </div>

  {# TEST EMAIL #}
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Send a test email'|trans }}</h3>
  <form class='pl-3' aria-label='{{ 'Send a test email'|trans }}' id='testEmailForm'>
    {{ App.Session.get('csrf')|csrf }}
    <input type='hidden' name='action' value='test'>
    <div class='input-group'>
      <input type='email' name='email' class='form-control col-md-12' value='{{ App.Users.userData.email|e('html_attr') }}' aria-label='{{ 'Email address'|trans }}'>
      <div class='input-group-append'>
        <button type='submit' class='btn btn-primary' data-action='send-test-email'>{{ 'Send'|trans }}</button>
      </div>
    </div>
  </form>
</div>

{# TAB 6 SECURITY #}
<div data-tabcontent='6' hidden>
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Security Settings'|trans }}</h3>
  <div class='pl-3 mb-5'>

    {% include 'binary-setting.html' with {'label': 'Users need validation by admin after registration'|trans, 'slug': 'admin_validate'} %}

    <div class='d-flex justify-content-between'>
      <label for='enforce_mfa' class='col-form-label'>{{ 'Enforce 2FA'|trans }}</label>
      <select class='form-control col-md-3' data-trigger='change' data-model='config' data-target='enforce_mfa' id='enforce_mfa'>
        {% for value, human in enforceMfaArr %}
          <option value='{{ value }}' {{- App.Config.configArr.enforce_mfa == value ? ' selected' }}>{{ human }}</option>
        {% endfor %}
      </select>
    </div>
    <p class='smallgray'>{{ 'Force certain accounts to enable multi-factor authentication.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='email_domain' class='col-form-label'>{{ 'Enforce a domain name for emails'|trans }}</label>
      <input id='email_domain' class='form-control col-md-3' type='text' placeholder='example.edu' value='{{ App.Config.configArr.email_domain }}' data-trigger='blur' data-model='config' data-target='email_domain' />
    </div>
    <p class='smallgray'>{{ 'Only email addresses at this domain will be allowed to register an account.'|trans }}<br>
    {{ 'You can add several domains by separating them with a comma.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='login_tries' class='col-form-label'>{{ 'Number of allowed login attempts:'|trans }}</label>
      <input class='form-control col-md-3' type='number' value='{{ App.Config.configArr.login_tries }}' data-trigger='blur' data-model='config' data-target='login_tries' id='login_tries' />
    </div>
    <p class='smallgray'>{{ '3 might be too few. See for yourself :)'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='autologout_time' class='col-form-label'>{{ 'Time after which inactive sessions are invalidated (force logout) (in seconds)'|trans }}</label>
      <input class='form-control col-md-3' type='number' value='{{ App.Config.configArr.autologout_time }}' data-trigger='blur' data-model='config' data-target='autologout_time' id='autologout_time' />
    </div>
    <p class='smallgray'>{{ 'Set to 0 to disable this feature.'|trans }}</p>
    <hr>

    {% include 'binary-setting.html' with {'label': 'Allow setting an authentication cookie'|trans, 'slug': 'remember_me_allowed', 'help': 'Disabling this setting will hide the "remember me" checkbox on login page.'|trans} %}

    {% include 'binary-setting.html' with {'label': 'Check the "remember me" box on login page by default'|trans, 'slug': 'remember_me_checked'} %}

    <div class='d-flex justify-content-between'>
      <label for='cookie_validity_time' class='col-form-label'>{{ 'Validity period of an authentication cookie (in minutes)'|trans }}</label>
      <input class='form-control col-md-3' type='number' value='{{ App.Config.configArr.cookie_validity_time }}' data-trigger='blur' data-model='config' data-target='cookie_validity_time' id='cookie_validity_time' />
    </div>
    <hr>
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Bruteforce login protection'|trans }}</h3>
  <div id='bruteforceDiv' class='pl-3'>
    <div class='d-flex justify-content-between'>
      <span>{{ '%d users are currently prevented from logging in from unknown devices.'|trans|format(nologinUsersCount) }}</span>
      <button type='submit' data-action='allowuntrusted' {{- nologinUsersCount == 0 ? ' disabled' }} class='btn btn-primary'>{{ 'Clear'|trans }}</button>
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <span>{{ '%d devices are currently denied authentication.'|trans|format(lockoutDevicesCount) }}</span>
      <button type='submit' data-action='clearlockedoutdevices' {{- lockoutDevicesCount == 0 ? ' disabled' }} class='btn btn-primary'>{{ 'Clear'|trans }}</button>
    </div>
    <hr>
  </div>
</div>

{# TAB 7 POLICIES #}
<div data-tabcontent='7' hidden>

  {% macro policy(title, slug, configArr, devMode) %}
    <h3 class='mb-3 p-2 pl-3 section-title'>{{ title|trans }}</h3>
    <div class='pl-3'>
      <div class='d-flex justify-content-between'>
        <label for='{{ slug }}_name' class='col-form-label'>{{ 'Link name'|trans }}</label>
        <input class='form-control col-md-3' data-trigger='blur' data-model='config' data-target='{{ slug }}_name' type='text' value='{{ configArr[slug ~ '_name'] }}' id='{{ slug }}_name' />
      </div>
      <hr>
      {% if not configArr[slug] %}
        {{ 'Note: the text below is a template and must be edited and saved.'|trans|msg('ok', false) }}
      {% endif %}
      {% if devMode -%}
        <!-- [html-validate-disable-block unique-landmark, element-permitted-content, no-deprecated-attr, prefer-native-element, no-unused-disable, require-sri: suppress errors from tinymce] -->
      {%- endif %}
      <textarea id='{{ slug }}Input' class='mceditable'>
        {{ configArr[slug]|default('Set your text here.')|raw }}
      </textarea>
      <div class='my-4 text-center'>
        <button type='button' data-action='patch-policy' data-confname='{{ slug }}' data-textarea='{{ slug }}Input' data-operation='save' class='btn btn-primary'>{{ 'Save'|trans }}</button>
        <button type='button' data-action='patch-policy' data-confname='{{ slug }}' data-textarea='{{ slug }}Input' data-operation='clear' class='btn btn-danger'>{{ 'Clear'|trans }}</button>
      </div>
    </div>
  {% endmacro %}

  {{ _self.policy('Privacy policy', 'privacy_policy', App.Config.configArr, App.devMode) }}
  {{ _self.policy('Terms of service', 'terms_of_service', App.Config.configArr, App.devMode) }}
  {{ _self.policy('Accessibility statement', 'a11y_statement', App.Config.configArr, App.devMode) }}
  {{ _self.policy('Legal notice', 'legal_notice', App.Config.configArr, App.devMode) }}

</div>

{# TAB 8 UPLOADS #}
<div data-tabcontent='8' hidden>
  <h3 class='p-2 pl-3 section-title'>{{ 'Information'|trans }}</h3>
  <div class='pl-3 mt-2 mb-5'>
    {% if uploadsStats.count_null_hash > 0 %}
      {{ 'Warning: %d files are missing a hash value. Fix it with %sbin/console uploads:check%s command.'|format(uploadsStats.count_null_hash, '<code>', '</code>')|msg('warning', false) }}
    {% endif %}
    {% if uploadsStats.count_null_filesize > 0 %}
      {{ 'Warning: %d files are missing a filesize value. Fix it with %sbin/console uploads:check%s command.'|format(uploadsStats.count_null_filesize, '<code>', '</code>')|msg('warning', false) }}
    {% endif %}
    {{ 'This instance has %d files uploaded using %s of disk space.'|trans|format(uploadsStats.count_all, uploadsStats.filesize_all|default(0)|formatBytes) }}
    {{ '%d files are stored on local filesystem and %d files are stored on S3.'|trans|format(uploadsStats.count_storage_local, uploadsStats.count_storage_s3) }}
  </div>

  <h3 class='p-2 pl-3 section-title'>{{ 'Configuration'|trans }}</h3>

  <div class='pl-3 mt-2 mb-5'>

    <div class='d-flex justify-content-between'>
      <label for='uploads_storage' class='col-form-label'>{{ 'Where user uploaded files are stored:'|trans }}</label>
      <select id='uploads_storage' data-trigger='change' data-model='config' data-target='uploads_storage' class='form-control col-md-3'>
        <option {{ App.Config.configArr.uploads_storage == '1' ? ' selected' }} value='1'>{{ 'Local filesystem'|trans }}</option>
        <option {{ App.Config.configArr.uploads_storage == '2' ? ' selected' }} value='2'>{{ 'S3 bucket'|trans }}</option>
      </select>
    </div>
    <p class='smallgray'>{{ 'You can select where uploaded files will be stored. The default is local storage but you can configure any S3 compatible object storage.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='s3_bucket_name' class='col-form-label'>S3 bucket name</label>
      <input class='form-control col-md-3' type='text' id='s3_bucket_name' placeholder='some-bucket-name' data-trigger='blur' data-model='config' data-target='s3_bucket_name' value='{{ App.Config.configArr.s3_bucket_name }}' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='s3_region' class='col-form-label'>S3 region</label>
      <input class='form-control col-md-3' type='text' id='s3_region' placeholder='fr-par' data-trigger='blur' data-model='config' data-target='s3_region' value='{{ App.Config.configArr.s3_region }}' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='s3_endpoint' class='col-form-label'>S3 endpoint</label>
      <input class='form-control col-md-3' type='url' id='s3_endpoint' placeholder='https://s3.example.org' data-trigger='blur' data-model='config' data-target='s3_endpoint' value='{{ App.Config.configArr.s3_endpoint }}' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='s3_path_prefix' class='col-form-label'>S3 path prefix (optional)</label>
      <input class='form-control col-md-3' type='text' id='s3_path_prefix' placeholder='uploads' data-trigger='blur' data-model='config' data-target='s3_path_prefix' value='{{ App.Config.configArr.s3_path_prefix }}' />
    </div>
    <hr>

    {% include 'binary-setting.html' with {'label': 'Verify TLS certificate'|trans, 'slug': 's3_verify_cert'} %}
    {% include 'binary-setting.html' with {'label': 'Use S3 Path-Style endpoint'|trans, 'slug': 's3_use_path_style_endpoint'} %}

  </div>
</div>

{# TAB 9 TIMESTAMP #}
<div data-tabcontent='9' hidden>
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Timestamping Configuration'|trans }}</h3>
  <div class='pl-3 mb-5'>
    {% include 'ts-config.html' %}
  </div>

  {# BLOXBERG #}
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Blockchain timestamp configuration'|trans }}</h3>
  <div class='pl-3'>

    {% include 'binary-setting.html' with {'label': 'Enable blockchain timestamping with Bloxberg'|trans, 'slug': 'blox_enabled'} %}
    {% include 'binary-setting.html' with {'label': 'Anonymize author for GDPR compliance'|trans, 'slug': 'blox_anon'} %}

  </div>

  {# KEEEX #}
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Keeex configuration'|trans }}</h3>
  <div class='pl-3'>
    <p class='smallgray'>{{ 'Requires a Keeex Fusion daemon running. %sSee documentation%s.'|trans|format("<a href='https://doc.elabftw.net/sysadmin-guide.html#configure-keeex'>", "</a>")|raw }}</p>

    {% include 'binary-setting.html' with {'label': 'Enable Keeex'|trans, 'slug': 'keeex_enabled'} %}

    <div class='d-flex justify-content-between'>
      <label for='keeex_host' class='col-form-label'>{{ 'Keeex host'|trans }}</label>
      <input class='form-control col-md-3' type='text' id='keeex_host' placeholder='keeex' data-trigger='blur' data-model='config' data-target='keeex_host' value='{{ App.Config.configArr.keeex_host }}' />
    </div>
    <p class='smallgray'>{{ 'Address (hostname or IP) of the Keeex service.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='keeex_port' class='col-form-label'>{{ 'Keeex port'|trans }}</label>
      <input class='form-control col-md-3' type='text' id='keeex_port' placeholder='8080' data-trigger='blur' data-model='config' data-target='keeex_port' value='{{ App.Config.configArr.keeex_port|default('8080') }}' />
    </div>
    <p class='smallgray'>{{ 'Default port is 8080.'|trans }}</p>
    <hr>
  </div>
</div>

{# TAB 10 LOCAL AUTH #}
<div data-tabcontent='10' hidden>
  <h3 class='p-2 pl-3 section-title'>{{ 'Local authentication configuration'|trans }}</h3>
  <div class='pl-3 mt-2 mb-5'>
    {% include 'binary-setting.html' with {'label': 'Enable local authentication'|trans, 'slug': 'local_auth_enabled', 'help': 'Toggle local authentication method (email + password). Warning: disabling this method might lock you out!'|trans} %}
    {% include 'binary-setting.html' with {'label': 'Enable local account creation'|trans, 'slug': 'local_register', 'help': 'Allow users to create accounts through the registration page. You probably want to disable this if you use an external authentication/provisioning method.'|trans} %}
    {% include 'binary-setting.html' with {'label': 'Show local login form'|trans, 'slug': 'local_login', 'help': 'This setting will hide the local authentication fields from the login page, but one can still display them by appending ?letmein to the login page URL.'|trans} %}
    {% include 'binary-setting.html' with {'label': 'Only allow a Sysadmin to login when local login form is hidden'|trans, 'slug': 'local_login_hidden_only_sysadmin', 'help': 'Enable this setting to prevent non-sysadmin users to authenticate using local auth when the form is hidden.'|trans} %}
    {% include 'binary-setting.html' with {'label': 'Only allow a Sysadmin to login with local login form'|trans, 'slug': 'local_login_only_sysadmin', 'help': 'Only a Sysadmin account can use the local login regardless if the local login form is hidden or not. Only activate it if you have another authentication method enabled for users.'|trans} %}
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Password policy'|trans }}</h3>
  <div class='pl-3'>
    <div class='d-flex justify-content-between'>
      <label for='min_password_length' class='col-form-label'>{{ 'Minimum password length'|trans }}</label>
      <input class='form-control col-md-3' type='number' value='{{ App.Config.configArr.min_password_length }}' data-trigger='blur' data-model='config' data-target='min_password_length' id='min_password_length' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='password_complexity_requirement' class='col-form-label'>{{ 'Password complexity requirement'|trans }}</label>
      <select class='form-control col-md-3' data-trigger='change' data-model='config' data-target='password_complexity_requirement' id='password_complexity_requirement'>
        {% for value, human in passwordComplexityArr %}
          <option value='{{ value }}' {{- App.Config.configArr.password_complexity_requirement == value ? ' selected' }}>{{ human }}</option>
        {% endfor %}
      </select>
    </div>
    <p class='smallgray'>{{ 'The minimum password length is always enforced.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='max_password_age_days' class='col-form-label'>{{ 'Maximum number of days since last password change'|trans }}</label>
      <input class='form-control col-md-3' type='number' value='{{ App.Config.configArr.max_password_age_days }}' data-trigger='blur' data-model='config' data-target='max_password_age_days' id='max_password_age_days' />
    </div>
    <p class='smallgray'>{{ 'Set to 0 to disable this feature.'|trans }}</p>
    <hr>
  </div>

</div>

{# TAB 11 SAML #}
<div data-tabcontent='11' hidden>
  <div class='mb-2 d-flex justify-content-between'>

    <p><a target='_blank' rel='noopener' class='external-link' href='https://doc.elabftw.net/saml.html'>{{ 'Link to documentation'|trans }}</a></p>
    {# VIEW METADATA.xml button: the div around the button is necessary or the button itself gets resized on small viewports #}
    <div>
      <a href='metadata.php' target='_blank' rel='noopener' class='btn btn-secondary'>{{ 'View metadata.xml'|trans }}</a>
    </div>
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'General settings'|trans }}</h3>
  <div class='pl-3 mb-5'>

    {% include 'binary-setting.html' with {'label': 'Enable SAML authentication'|trans, 'slug': 'saml_toggle'} %}
    {% include 'binary-setting.html' with {'label': 'Strict mode'|trans, 'slug': 'saml_strict'} %}
    {% include 'binary-setting.html' with {'label': 'Debug mode'|trans, 'slug': 'saml_debug'} %}

  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Service provider'|trans }}</h3>
  <div class='pl-3 mb-5'>

    <div class='d-flex justify-content-between'>
      <label for='saml_baseurl' class='col-form-label'>{{ 'Base URL'|trans }}</label>
      <input class='form-control col-md-3' type='url' id='saml_baseurl' data-trigger='blur' data-model='config' data-target='saml_baseurl' placeholder='https://elabftw.example.org' value='{{ App.Config.configArr.saml_baseurl }}' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='saml_entityid' class='col-form-label'>EntityId</label>
      <input class='form-control col-md-3' type='text' id='saml_entityid' data-trigger='blur' data-model='config' data-target='saml_entityid' placeholder='https://elabftw.example.org' value='{{ App.Config.configArr.saml_entityid }}' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='saml_acs_binding' class='col-form-label'>Assertion Consumer Service binding (only POST supported)</label>
      <select class='form-control col-md-3' id='saml_acs_binding' data-trigger='change' data-model='config' data-target='saml_acs_binding'>
        <option value='urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect' {{ App.Config.configArr.saml_acs_binding == 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect' ? 'selected' }}>Redirect</option>
        <option value='urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST' {{ App.Config.configArr.saml_acs_binding == 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST' ? 'selected' }}>POST</option>
      </select>
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='saml_slo_binding' class='col-form-label'>Single Logout Service binding (only Redirect supported)</label>
      <select class='form-control col-md-3' id='saml_slo_binding' data-trigger='change' data-model='config' data-target='saml_slo_binding'>
        <option value='urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect' {{ App.Config.configArr.saml_slo_binding == 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect' ? 'selected' }}>Redirect</option>
        <option value='urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST' {{ App.Config.configArr.saml_slo_binding == 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST' ? 'selected' }}>POST</option>
      </select>
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='saml_nameidformat' class='col-form-label'>NameIDFormat. Default is "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress".</label>
      <input class='form-control col-md-3' type='text' id='saml_nameidformat' data-trigger='blur' data-model='config' data-target='saml_nameidformat' placeholder='urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' value='{{ App.Config.configArr.saml_nameidformat }}' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <div>
        <label for='x509' class='col-form-label'>x509 Certificate in PEM format</label>
        <input type='file' data-action='load-file-on-change' data-ignore='1' data-target='x509' class='form-control' aria-label='File upload: x509 Certificate in PEM format' />
      </div>
      <textarea class='form-control col-md-3' id='x509' data-trigger='blur' data-model='config' data-target='saml_x509'>{{ App.Config.configArr.saml_x509 }}</textarea>
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <div>
        <label for='saml_privatekey' class='col-form-label'>x509 Certificate private key</label>
        <input type='file' data-action='load-file-on-change' data-ignore='1' data-target='saml_privatekey' class='form-control' aria-label='File upload: x509 Certificate private key' />
      </div>
      <textarea class='form-control col-md-3' id='saml_privatekey' data-trigger='blur' data-model='config' data-target='saml_privatekey'>{{ App.Config.configArr.saml_privatekey }}</textarea>
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <div>
        <label for='x509_new' class='col-form-label'>Rollover x509 Certificate in PEM format (only published in metadata, not used)</label>
        <input type='file' data-action='load-file-on-change' data-ignore='1' data-target='x509_new' class='form-control' aria-label='File upload: Rollover x509 Certificate in PEM format' />
      </div>
      <textarea class='form-control col-md-3' id='x509_new' data-trigger='blur' data-model='config' data-target='saml_x509_new'>{{ App.Config.configArr.saml_x509_new }}</textarea>
    </div>
    <hr>

  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Teams settings'|trans }}</h3>
  <div class='pl-3 mb-5'>

    {% include 'binary-setting.html' with {'label': 'Fallback to internal id if existing user cannot be matched with email'|trans, 'slug': 'saml_fallback_orgid'} %}
    {% include 'binary-setting.html' with {'label': 'If user is matched with internal id, update the email sent by IDP?'|trans, 'slug': 'saml_sync_email_idp'} %}
    {% include 'binary-setting.html' with {'label': 'Synchronize the local teams with the teams sent by IDP'|trans, 'slug': 'saml_sync_teams'} %}
    {% include 'binary-setting.html' with {'label': "Create team sent by IDP if it doesn't exist already"|trans, 'slug': 'saml_team_create', 'affix': '1'} %}

    <div class='d-flex justify-content-between'>
      <label for='saml_team_default' class='col-form-label'>{{ 'If no team attribute is found, to which team user is assigned?'|trans }}</label>
      <select class='form-control col-md-3' data-trigger='change' data-model='config' data-target='saml_team_default' id='saml_team_default'>
        {% for team in teamsArr %}
          <option {{ team.id == App.Config.configArr.saml_team_default ? 'selected' }} value='{{ team.id }}'>{{ team.name }}</option>
        {% endfor %}
        <option {{ 0 == App.Config.configArr.saml_team_default ? 'selected' }} value='0'>{{ 'Throw error'|trans }}</option>
        <option {{ '-1' == App.Config.configArr.saml_team_default ? 'selected' }} value='-1'>{{ 'Let user select a team'|trans }}</option>
      </select>
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='saml_user_default' class='col-form-label'>{{ "If the user doesn't exist yet, what to do?"|trans }}</label>
      <select class='form-control col-md-3' data-trigger='change' data-model='config' data-target='saml_user_default' id='saml_user_default'>
        <option {{ 1 == App.Config.configArr.saml_user_default ? 'selected' }} value='1'>{{ 'Create the user on the fly'|trans }}</option>
        <option {{ 0 == App.Config.configArr.saml_user_default ? 'selected' }} value='0'>{{ 'Throw error, allowing a sysadmin to create the user'|trans }}</option>
      </select>
    </div>
    <hr>
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Security settings'|trans }}</h3>
  <div class='pl-3 mb-5'>

    {% for setting in samlSecuritySettings %}
      {% include 'binary-setting.html' with {'label': setting.label, 'slug': setting.slug} %}
    {% endfor %}
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Identity providers'|trans }}</h3>
  <div class='pl-3 mb-5'>
    <h5 id='addIdpsSourcesInputLabel'>{{ 'Add IDP(s) from URL'|trans }}</h5>
    <p class='smallgray'>{{ 'You can register a remote URL corresponding to an XML metadata file containing a list of IDPs or a single IDP metadata. If Auto-refresh is enabled, the IDPs metadata will be refreshed every 24h automatically.'|trans }}</p>
    <ul class='list-group' id='idpsSourcesDiv'>
      <li class='list-group-item'>
        <div class='input-group'>
          <div class='input-group-prepend'>
            <span class='input-group-text'>+</span>
          </div>
          <input id='addIdpsSourcesInput' aria-labelledby='addIdpsSourcesInputLabel' class='form-control' type='url' placeholder='https://www.aai.example.com/idps.xml' />
          <div class='input-group-append'>
            <button class='btn btn-primary' data-action='save-idps-source' type='button'>{{ 'Save'|trans }}</button>
          </div>
        </div>
      </li>
      {% for source in idpsSources %}
      <li class='list-group-item'>
        <div class='d-flex'>
          <a target='_blank' rel='noopener' class='external-link' href='{{ source.url }}'>{{ source.url }}</a>
          <div class='ml-auto'>
            <label for='autorefreshIdpsSource-{{ source.id }}' class='col-form-label clickable'>{{ 'Auto-refresh'|trans }}</label>
            <label class='switch ucp-align'>
              <input type='checkbox' id='autorefreshIdpsSource-{{ source.id }}' {{ source.auto_refresh == 1 ? "checked='checked'" }} autocomplete='off' data-trigger='change' data-model='idps_sources/{{ source.id }}' data-target='auto_refresh'>
              <span class='slider'></span>
            </label>
            <button type='button' class='btn btn-sm btn-primary mx-2' data-action='refresh-idps-source' data-id='{{ source.id }}'>{{ 'Refresh'|trans }}</button>
            <button type='button' class='btn btn-sm btn-secondary mx-2' data-action='enable-idps-with-source' data-id='{{ source.id }}'>{{ 'Enable all'|trans }}</button>
            <button type='button' class='btn btn-sm btn-secondary mx-2' data-action='disable-idps-with-source' data-id='{{ source.id }}'>{{ 'Disable all'|trans }}</button>
            <button type='button' class='btn btn-sm btn-danger mx-2' data-action='delete-idps-source' data-id='{{ source.id }}'>{{ 'Delete'|trans }}</button>
          </div>
        </div>
        <div class='smallgray'>{{ 'Associated with %d IDPs (%d enabled)'|trans|format(source.idps_count, source.idps_count_enabled) }}</div>
      </li>
      {% endfor %}
    </ul>

    <div class='my-3'>
      <h5>{{ 'Add IDP manually'|trans }}</h5>
      <p class='col-form-label'>{{ 'You can also add a new IDP manually. A manually added IDP will not have its metadata automatically refreshed.'|trans }}</p>
      {# CREATE NEW BUTTON the div around the button is necessary or the button itself gets resized on small viewports #}
      <div>
        <button type='button' class='btn btn-primary' data-action='toggle-modal' data-target='idpModal'>{{ 'Add new IDP'|trans }}</button>
      </div>
    </div>

    <div class='my-3'>
      <h5>{{ 'IDPs list'|trans }}</h5>
      <p class='col-form-label'>{{ 'Currently %d IDPs are configured.'|trans|format(idpsArr|length) }}</p>
      {% include 'filter-input-snippet.html' with {'target': 'idpsDiv', 'targetType': 'li'} %}
      <ul class='list-group' id='idpsDiv'>
        {% for idp in idpsArr %}
          <li class='list-group-item'>
            <h4 data-action='toggle-next' data-opened-icon='fa-caret-down' data-closed-icon='fa-caret-right' class='d-inline togglable-section-title' tabindex='0' role='button'>
              <i class='fas fa-caret-right fa-fw mr-2'></i>
              <label class='switch ucp-align'>
                <input type='checkbox' autocomplete='off' data-trigger='change' data-model='idps/{{ idp.id }}' data-target='enabled' {{ idp.enabled ? 'checked="checked"' }} id='enabled_{{ idp.id }}'>
                <span class='slider'></span>
              </label>
              {{ idp.name|upper }} ({{ idp.entityid }})
            </h4>

            <div class='pl-3 m-2' hidden>
              <button type='button' class='btn btn-primary' data-action='display-idp-modal' data-id='{{ idp.id }}'>{{ 'Edit'|trans }}</button>
              <button type='button' class='btn btn-danger' data-action='destroy-idp' data-id='{{ idp.id }}'>{{ 'Delete'|trans }}</button>

              {% if idp.source_url %}
                <div class='d-flex justify-content-between'>
                  <label for='source_{{ idp.id }}' class='col-form-label'>{{ 'Source'|trans }}</label>
                  <input class='form-control col-md-3' type='url' disabled readonly id='source_{{ idp.id }}' value='{{ idp.source_url }}' />
                </div>
                <hr>
              {% endif %}

            </div>
          </li>
        {% endfor %}
      </ul>
    </div>
  </div>

</div>

{# TAB 12 LDAP #}
<div data-tabcontent='12' id='ldapSettings' hidden>
  <p><a target='_blank' rel='noopener' class='external-link' href='https://doc.elabftw.net/ldap.html'>{{ 'Link to documentation'|trans }}</i></a></p>
  <h3 class='p-2 pl-3 section-title'>{{ 'LDAP server configuration'|trans }}</h3>

  <div class='pl-3 mt-2 mb-5'>

    {% include 'binary-setting.html' with {'label': 'Toggle LDAP login'|trans, 'slug': 'ldap_toggle'} %}

    <div class='d-flex justify-content-between'>
      <label for='ldap_scheme' class='col-form-label'>{{ 'LDAP Scheme'|trans }}</label>
      <input class='form-control col-md-3' type='text' data-trigger='blur' data-model='config' data-target='ldap_scheme' placeholder='ldap' value='{{ App.Config.configArr.ldap_scheme }}' id='ldap_scheme' />
    </div>
    <p class='smallgray'>{{ 'Ldap scheme can be set regardless of the SSL/TLS settings. Valid values are "ldap" or "ldaps". Default is "ldap".'|trans }}</p>
    <hr>


    <div class='d-flex justify-content-between'>
      <label for='ldap_host' class='col-form-label'>{{ 'LDAP Host'|trans }}</label>
      <input class='form-control col-md-3' type='text' data-trigger='blur' data-model='config' data-target='ldap_host' placeholder='ldap' value='{{ App.Config.configArr.ldap_host }}' id='ldap_host' />
    </div>
    <p class='smallgray'>{{ 'Domain name or IP address. You can specify multiple entries for redundancy, separated by commas.'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='ldap_port' class='col-form-label'>{{ 'LDAP Port'|trans }}</label>
      <input class='form-control col-md-3' type='text' data-trigger='blur' data-model='config' data-target='ldap_port' placeholder='389' value='{{ App.Config.configArr.ldap_port }}' id='ldap_port' />
    </div>
    <p class='smallgray'>{{ 'Default: 389 LDAPS: 636'|trans }}</p>
    <hr>

    {% include 'binary-setting.html' with {'label': 'Use TLS'|trans, 'slug': 'ldap_use_tls'} %}

    <div class='d-flex justify-content-between'>
      <label for='ldap_base_dn' class='col-form-label'>LDAP Base DN</label>
      <input class='form-control col-md-3' type='text' data-trigger='blur' data-model='config' data-target='ldap_base_dn' placeholder='dc=example,dc=com' value='{{ App.Config.configArr.ldap_base_dn }}' id='ldap_base_dn' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='ldap_username' class='col-form-label'>LDAP {{ 'Username'|trans }} (keep empty to use anonymous bind)</label>
      <input class='form-control col-md-3' type='text' data-trigger='blur' data-model='config' data-target='ldap_username' autocomplete='off' placeholder='cn=admin,dc=example,dc=com' value='{{ App.Config.configArr.ldap_username }}' id='ldap_username' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <!-- [html-validate-disable no-missing-references: if there is an ldap_password, the input is not shown] -->
      <label for='ldap_password' class='col-form-label'>LDAP {{ 'Password'|trans }}</label>
      {% if App.Config.configArr.ldap_password|length == 0 %}
        <div class='input-group col-md-3 p-0'>
          <input class='form-control' type='password' data-trigger='blur' data-model='config' data-target='ldap_password' id='ldap_password' autocomplete='off' />
          <div class='input-group-append'>
            <button type='button' class='btn btn-light input-border' data-action='toggle-password' data-target='ldap_password' title='{{ 'Show password'|trans }}' aria-label='{{ 'Show password'|trans }}'><i class='fas fa-eye' aria-hidden='true'></i></button>
          </div>
        </div>
      {% else %}
        <p>
        {{ 'A password is already set.'|trans }} <button type='button' class='btn btn-danger btn-sm' data-action='clear-password' data-target='ldap' data-reload='ldapSettings'>{{ 'Clear'|trans }}</button>
        </p>
      {% endif %}
    </div>
    <hr>

  </div>

  <h3 class='p-2 pl-3 section-title'>{{ 'eLabFTW LDAP configuration'|trans }}</h3>

  <div class='pl-3 mt-2'>
    <div class='d-flex justify-content-between'>
      <label for='ldap_search_attr' class='col-form-label'>{{ "By which LDAP attribute the user will be found (default is 'mail')."|trans }}</label>
      <input class='form-control col-md-3' type='text' data-trigger='blur' data-model='config' data-target='ldap_search_attr' placeholder='mail' value='{{ App.Config.configArr.ldap_search_attr }}' id='ldap_search_attr' />
    </div>
    <p class='smallgray'>{{ 'You can search for several attributes by separating them with a comma (e.g. uid,mail).'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='ldap-team' class='col-form-label'>{{ 'What attribute to look for the team name'|trans }}</label>
      <input class='form-control col-md-3' data-trigger='blur' data-model='config' data-target='ldap_team' type='text' id='ldap-team' value='{{ App.Config.configArr.ldap_team }}' />
    </div>
    <hr>

    {% include 'binary-setting.html' with {'label': "Create team sent by server if it doesn't exist already"|trans, 'slug': 'saml_team_create', 'affix': '2'} %}

    <div class='d-flex justify-content-between'>
      <label for='ldap-team-default' class='col-form-label'>{{ 'If no team attribute is found, to which team user is assigned?'|trans }}</label>
      <select class='form-control col-md-3' data-trigger='change' data-model='config' data-target='saml_team_default' id='ldap-team-default'>
        {% for team in teamsArr %}
          <option {{ team.id == App.Config.configArr.saml_team_default ? 'selected' }} value='{{ team.id }}'>{{ team.name }}</option>
        {% endfor %}
        <option {{ 0 == App.Config.configArr.saml_team_default ? 'selected' }} value='0'>{{ 'Throw error'|trans }}</option>
        <option {{ '-1' == App.Config.configArr.saml_team_default ? 'selected' }} value='-1'>{{ 'Let user select a team'|trans }}</option>
      </select>
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='ldap-user-default' class='col-form-label'>{{ "If the user doesn't exist yet, what to do?"|trans }}</label>
      <select class='form-control col-md-3' data-trigger='change' data-model='config' data-target='saml_user_default' name='saml_user_default' id='ldap-user-default'>
        <option {{ 1 == App.Config.configArr.saml_user_default ? 'selected' }} value='1'>{{ 'Create the user on the fly'|trans }}</option>
        <option {{ 0 == App.Config.configArr.saml_user_default ? 'selected' }} value='0'>{{ 'Throw error, allowing a sysadmin to create the user'|trans }}</option>
      </select>
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='ldap-email' class='col-form-label'>{{ 'What attribute to look for the email'|trans }}</label>
      <input class='form-control col-md-3' type='text' data-trigger='blur' data-model='config' data-target='ldap_email' id='ldap-email' placeholder='mail' value='{{ App.Config.configArr.ldap_email }}' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='ldap-firstname' class='col-form-label'>{{ 'What attribute to look for the firstname'|trans }}</label>
      <input class='form-control col-md-3' type='text' id='ldap-firstname' placeholder='givenname' data-trigger='blur' data-model='config' data-target='ldap_firstname' value='{{ App.Config.configArr.ldap_firstname }}' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='ldap-lastname' class='col-form-label'>{{ 'What attribute to look for the lastname'|trans }}</label>
      <input class='form-control col-md-3' type='text' id='ldap-lastname' placeholder='sn' data-trigger='blur' data-model='config' data-target='ldap_lastname' value='{{ App.Config.configArr.ldap_lastname }}' />
    </div>
    <hr>
  </div>
</div>

{# TAB 13 EXTERNAL AUTH #}
<div data-tabcontent='13' hidden>
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'External authentication mapping'|trans }}</h3>
  <div class='pl-3'>
    <p class='smallgray'>{{ 'If authentication is handled by an upstream server, configure here the request headers mappings and behaviors.'|trans }}</p>

    <div class='d-flex justify-content-between'>
      <label for='extauth_remote_user' class='col-form-label'>{{ 'Remote user'|trans }}</label>
      <input class='form-control col-md-3' type='text' placeholder='REMOTE_USER' value='{{ App.Config.configArr.extauth_remote_user }}' data-trigger='blur' data-model='config' data-target='extauth_remote_user' id='extauth_remote_user' />
    </div>
    <p class='smallgray'>{{ 'Use this to detect if the user is logged in from upstream server (value is not used, only presence).'|trans }}</p>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='extauth_firstname' class='col-form-label'>{{ 'Firstname'|trans }}</label>
      <input class='form-control col-md-3' type='text' placeholder='MELLON_givenName' value='{{ App.Config.configArr.extauth_firstname }}' data-trigger='blur' data-model='config' data-target='extauth_firstname' id='extauth_firstname' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='extauth_lastname' class='col-form-label'>{{ 'Lastname'|trans }}</label>
      <input class='form-control col-md-3' type='text' placeholder='MELLON_sn' value='{{ App.Config.configArr.extauth_lastname }}' data-trigger='blur' data-model='config' data-target='extauth_lastname' id='extauth_lastname' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='extauth_email' class='col-form-label'>{{ 'Email'|trans }}</label>
      <input class='form-control col-md-3' type='text' placeholder='MELLON_mail' value='{{ App.Config.configArr.extauth_email }}' data-trigger='blur' data-model='config' data-target='extauth_email' id='extauth_email' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='extauth_teams' class='col-form-label'>{{ 'Teams'|trans }}</label>
      <input class='form-control col-md-3' type='text' placeholder='MELLON_ou' value='{{ App.Config.configArr.extauth_teams }}' data-trigger='blur' data-model='config' data-target='extauth_teams' id='extauth_teams' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='logout_url' class='col-form-label'>{{ 'Logout URL'|trans }}</label>
      <input class='form-control col-md-3' type='url' placeholder='https://idp.example.edu/saml/logout' value='{{ App.Config.configArr.logout_url }}' data-trigger='blur' data-model='config' data-target='logout_url' id='logout_url' />
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='extauth-team-default' class='col-form-label'>{{ 'If no team attribute is found, to which team user is assigned?'|trans }}</label>
      <select class='form-control col-md-3' data-trigger='change' data-model='config' data-target='saml_team_default' id='extauth-team-default'>
        {% for team in teamsArr %}
          <option {{ team.id == App.Config.configArr.saml_team_default ? 'selected' }} value='{{ team.id }}'>{{ team.name }}</option>
        {% endfor %}
        <option {{ 0 == App.Config.configArr.saml_team_default ? 'selected' }} value='0'>{{ 'Throw error'|trans }}</option>
      </select>
    </div>
    <hr>

    <div class='d-flex justify-content-between'>
      <label for='extauth-user-default' class='col-form-label'>{{ "If the user doesn't exist yet, what to do?"|trans }}</label>
      <select class='form-control col-md-3' data-trigger='change' data-model='config' data-target='saml_user_default' id='extauth-user-default'>
        <option {{ 1 == App.Config.configArr.saml_user_default ? 'selected' }} value='1'>{{ 'Create the user on the fly'|trans }}</option>
        <option {{ 0 == App.Config.configArr.saml_user_default ? 'selected' }} value='0'>{{ 'Throw error, allowing a sysadmin to create the user'|trans }}</option>
      </select>
    </div>
    <hr>

    {% include 'binary-setting.html' with {'label': "Create team sent by server if it doesn't exist already"|trans, 'slug': 'saml_team_create', 'affix': '3'} %}
  </div>
</div>

{# TAB 14: AUDIT LOGS #}
<div data-tabcontent='14' hidden>
  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Audit Logs configuration'|trans }}</h3>
  <div class='pl-3 mb-5'>
    {% include 'binary-setting.html' with {'label': 'Emit audit logs with PHP error log'|trans, 'slug': 'emit_audit_logs', 'help': 'Enable to include audit logs events as INFO event in PHP logs.'|trans} %}
  </div>

  <h3 class='mb-3 p-2 pl-3 section-title'>{{ 'Audit Logs'|trans }}</h3>
  <div class='pl-3 mb-5'>
    <p id='auditLogsTableLabel'>{{ 'This table lists the most recent events recorded in the application and worth keeping a trace of.'|trans }}</p>
    {# Refresh button #}
    <div class='text-center'>
      <button type='button' aria-label='{{ 'Refresh'|trans }}' class='btn btn-secondary btn-sm mb-2' data-action='reload-on-click' data-target='auditLogsTable'><i class='fas fa-rotate color-white mr-1'></i>{{ 'Refresh'|trans }}</button>
    </div>
    {# Logs are presented in a sortable table #}
    {% include 'filter-input-snippet.html' with {'target': 'auditLogsTable'} %}
    <div class='table-container'>
      <table class='table' aria-labelledby='auditLogsTableLabel' data-table-sort='true'>
        <thead>
          <tr>
            <th scope='col'>{{ 'Category'|trans }}</th>
            <th scope='col'>{{ 'Created at'|trans }}</th>
            <th scope='col'>{{ 'Content'|trans }}</th>
            <th scope='col'>{{ 'Actor'|trans }}</th>
            <th scope='col'>{{ 'Target user'|trans }}</th>
          </tr>
        </thead>
        <tbody id='auditLogsTable'>
          {% for log in auditLogsArr %}
            <tr>
              <td>{{ log.category }}</td>
              <td><span class='relative-moment' title='{{ log.created_at }}'></span></td>
              <td>{{ log.body }}</td>
              <td>
                {%- if log.requester_userid != 0 -%}
                  <a class='p-1 rounded hl-hover-gray' href='?tab=3&amp;q=&amp;userid={{ log.requester_userid }}'>{{ log.requester_userid }}</a>
                {%- else -%}
                  <span class='p-1'>&ndash;</span>
                {%- endif -%}
              </td>
              <td>
                {%- if log.target_userid != 0 -%}
                  <a class='p-1 rounded hl-hover-gray' href='?tab=3&amp;q=&amp;userid={{ log.target_userid }}'>{{ log.target_userid }}</a>
                {%- else -%}
                  <span class='p-1'>&ndash;</span>
                {%- endif -%}
              </td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
</div>

<div id='info' data-page='sysconfig'></div>
{% endblock body %}
